package com.lyl.novel.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageMethod;
import com.lyl.novel.dao.NovelDao;
import com.lyl.novel.model.dto.ListNovelDTO;
import com.lyl.novel.model.entity.Novel;
import com.lyl.novel.service.NovelService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 小说表(Novel)表服务实现类
 *
 * @author Mr Luo
 * @since 2022-08-22 16:10:24
 */
@Service("novelService")
@RequiredArgsConstructor
public class NovelServiceImpl extends ServiceImpl<NovelDao, Novel> implements NovelService {
    private final NovelDao novelDao;

    @Override
    public PageInfo<Novel> list(Integer pageNo, Integer pageSize, ListNovelDTO dto) {
        PageMethod.startPage(pageNo, pageSize);
        return PageInfo.of(novelDao.list(dto));
    }

    @Override
    public List<String> getNovelTypeList() {
        return lambdaQuery().select(Novel::getType).groupBy(Novel::getType)
                .list().stream().map(Novel::getType)
                .filter(ObjectUtil::isNotEmpty)
                .distinct().collect(Collectors.toList());
    }
}

